package com.shaw.workrecord.controller;

import com.shaw.workrecord.entity.PageRequest;
import com.shaw.workrecord.entity.PageResponse;
import com.shaw.workrecord.entity.ResponseBean;
import com.shaw.workrecord.pojo.game.request.RoomAddRequest;
import com.shaw.workrecord.pojo.game.request.RoomEditRequest;
import com.shaw.workrecord.pojo.game.response.RoomResponse;
import com.shaw.workrecord.service.IRoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author jiangjunhui
 * @description
 * @date 2022/9/15 10:31
 */
@Api(tags = "游戏房间管理")
@RestController
public class RoomController {

    @Autowired
    private IRoomService service;

    @GetMapping("/room")
    @ApiOperation("获取房间列表")
    public ResponseBean<PageResponse<RoomResponse>> getRoomPage(PageRequest request) {
        return ResponseBean.success(service.getRoomPage(request));
    }

    @PostMapping("/room")
    @ApiOperation("新增房间")
    public ResponseBean<Boolean> addRoom(@RequestBody RoomAddRequest request) {
        if (service.addRoom(request)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("创建房间失败");
    }

    @PutMapping("/room")
    @ApiOperation("编辑房间")
    public ResponseBean<Boolean> editRoom(@RequestBody RoomEditRequest request) {
        if (service.editRoom(request)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("编辑房间失败");
    }

    @DeleteMapping("/room/{id}")
    @ApiOperation("新增房间")
    public ResponseBean<Boolean> removeRoom(@PathVariable("id") Long id) {
        if (service.deleteRoom(id)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("删除房间失败");
    }
}
